﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Kinlo.Model
{

    public class T
    {
        public Int16 ReadCodeCMD { get; set; }
        public Int16 ReadBeforWeightCMD { get; set; }
        public Int16 ReadAfterWeightCMD { get; set; }
        public Int16 ReadSupplementCMD { get; set; }
    }

    public class T1
    { 
        public bool HaveBattry { get; set; }
        public bool Vacaumm_Test_ok { get; set; }
        public bool BeforeWeight_ok { get; set; }
        public byte demo1 { get; set; }
        public float BeforWeight { get; set; }
        public float AfterWeight { get; set; }
        public float Weight { get; set; }
        public bool Weight_OK { get; set; }
        public byte demo2 { get; set; } 
        public float Offset { get; set; }
    }
    public class T2
    {
        public bool HaveBattry { get; set; }
        public bool Vacaumm_Test_ok { get; set; }
        public bool PoleEarOK { get; set; }
        public byte demo1 { get; set; }
        public float BeforWeight { get; set; }
    }

    public class FixT1
    {
        public FixT1()
        {
        }
        public bool HaveBattry { get; set; }
        public bool Vacaumm_Test_ok { get; set; }
        public byte demo1 { get; set; }
        public float BeforWeight { get; set; }
        public float AfterWeight { get; set; }
        public float Weight { get; set; }
        public float Offset { get; set; }
        public bool Weight_OK { get; set; }
        public bool Code_OK { get; set; }
        public byte demo2 { get; set; }
        public string Code { get; set; }
    }




    public static class Helper
    {
        public static FixT1 ConvertToFixT1(this T1 t1)
        {
            var fixT1 = new FixT1();
            fixT1.HaveBattry = t1.HaveBattry;
            fixT1.Vacaumm_Test_ok = t1.Vacaumm_Test_ok;
            fixT1.demo1 = t1.demo1;
            fixT1.BeforWeight = t1.BeforWeight;
            fixT1.AfterWeight = t1.AfterWeight;
            fixT1.Weight = t1.Weight;
            fixT1.Offset = t1.Offset;
            fixT1.Weight_OK = t1.Weight_OK;  

            return fixT1;
        }
        public static string ConvertByteToStrinig(byte[] b)
        {
            var content= Encoding.Default.GetString(b, 2, b.Length - 2).Replace("\0", "").Trim();
            var index = content.IndexOf("\r");
            if (index > 0)
            {
                return content.Substring(0, index);
            }
            return content;
        }
    }
}
